import httpInstance from "@/utils/http"

// 新增购物车商品
export const addCartAPI = (data: { skuId: string, count: number }) => {
    return httpInstance({
        method: 'POST',
        url: '/member/cart',
        data,
    });
};

// 获取购物车列表
export const getCartListAPI = () => {
    const controller = new AbortController();
    const response = httpInstance({
        method: 'GET',
        url: '/member/cart',
        signal: controller.signal,
    });
    return { response, controller };
};

// 删除购物车商品
export const deleteCartAPI = (ids: Array<string>) => {
    return httpInstance({
        method: 'DELETE',
        url: '/member/cart',
        data: { ids },
    });
};

// 合并购物车商品到数据库
export const mergeCartAPI = (data: Array<{ skuId: string, selected: string, count: number }>) => {
    return httpInstance({
        url: '/member/cart/merge',
        method: 'POST',
        data,
    });
};